<template>
	<view class="wrap">
		<view class="search">
			<u-search placeholder="输入地址搜索" v-model="cdeliveradd" @custom="search" @search="search"></u-search>
		</view>
		<view v-for="(item,index) in addressList" :key="index" @click="xzAddress(item)">
			<view v-if="addressList.length" style="margin: 10px;padding: 10px; background: #fff;
			border-radius: 10px;display: flex;margin-bottom: 10px;">
			<view style="margin: auto;margin-right: 10px;width: 80rpx;">
				<view v-if="item.bdefault=='1'" style="width: 80rpx;height: 80rpx; border-radius: 50%;border: 1px solid orange;background: orange;
				color: #fff;font-weight: bold;text-align: center;line-height: 80rpx;">
					默认
				</view>
				<view v-else style="width: 80rpx;height: 80rpx; border-radius: 50%;border: 1px solid orange;
				color: orange;font-weight: bold;text-align: center;line-height: 80rpx;">
					{{item.cdeliverunit?item.cdeliverunit.slice(0, 2):''}}
				</view>
			</view>
			<view style="flex: 1;margin: auto 0;">
				<view style="display: flex;align-items: center;">
					<view style="font-weight: bold;margin-right: 18rpx;">{{item.cdeliverunit || ''}}</view>
					<view >{{item.cenglishadd4 || ''}}</view>
					<view v-if="item.bdefault=='1'" style="border: 1px solid orange; color: orange;padding: 5rpx;
					font-size: 18rpx;border-radius: 5px;margin-left: 18rpx;;">默认</view>
				</view>
				<view style="margin-top: 10rpx;font-size: 26rpx;">
					{{item.cdeliveradd || ''}}
				</view>
			</view>
			</view>
		</view>
		<view v-if="!addressList.length" style="padding-top: 50%;">
			<u-empty  mode="address"  ></u-empty>	
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cdeliveradd:'',
				addressList:[],
				show: false,
				ccuscode:'',
				form: {},
				tagList: [{
						value: '家',
						checked: false
					},
					{
						value: '公司',
						checked: false
					},
					{
						value: '学校',
						checked: false
					}
				]
			};
		},
		onLoad(data) {
			console.log(data,'data=====');
			// this.$u.api.shop.cusAddress({code:this.vuex_basCus.code})
			// 	.then(res => {
			// 		this.form = res
			// 		this.form.picker = `${res.province?res.province:''} ${res.city?res.city:''} ${res.county?res.county:''}`
			// 		console.log(res,'res======');
			// 	});
			let ccuscode = data.ccuscode?data.ccuscode:this.vuex_basCus.code
			this.ccuscode = data.ccuscode
			this.$u.api.shop.addressListData({ccuscode,pageNo: 1,pageSize: 100})
				.then(res => {
					console.log(res,'res======');
					this.addressList = res.list
				});
		},
		methods: {
			xzAddress(item){
				if(this.ccuscode){
					uni.$emit('xzaddressData', item);
					uni.navigateBack({
						delta: 1,
					})
				}
			},
			search(){
				this.$u.api.shop.addressListData({
					cdeliveradd:this.cdeliveradd,
					ccuscode:this.ccuscode?this.ccuscode:this.vuex_basCus.code,
					pageNo: 1,
					pageSize: 100,
					})
					.then(res => {
						console.log(res,'res======');
						this.addressList = res.list
					});
			},
			showRegionPicker() {
				this.show = true;
			},
			save() {
				console.log(this.form);
			},
			confirm(e) {
				this.form.picker = e.province.label + " " + e.city.label + " " + e.area.label
			},
			tagSelect(value, checked, index) {
				checked == false ? this.form.tags = value : this.form.tags = '';
				//只能选择一个标签
				this.tagList.forEach((tag, i) => {
					if (i == index) {
						this.tagList[i].checked = !this.tagList[i].checked
					} else {
						this.tagList[i].checked = false
					}
				})
			},

		}
	};
</script>

<style lang="scss" scoped>
	/deep/ .line {
		color: $u-light-color;
		font-size: 28rpx;
	}

	.wrap {
		background-color: #f2f2f2;

		.top {
			background-color: #ffffff;
			border-top: solid 2rpx $u-border-color;
			padding: 22rpx;

			.item {
				display: flex;
				font-size: 26rpx;
				line-height: 100rpx;
				align-items: center;
				border-bottom: solid 2rpx $u-border-color;

				.left {
					width: 180rpx;
				}

				input {
					text-align: left;
				}
			}

			.address {
				padding: 20rpx 0;

				textarea {
					// width: 100%;
					height: 100rpx;
					// background-color: #f7f7f7;
					line-height: 60rpx;
					// margin: 40rpx auto;
					// padding: 20rpx;
				}
			}

			.site-clipboard {
				padding-right: 40rpx;

				textarea {
					// width: 100%;
					height: 150rpx;
					// background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}

				.clipboard {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: $u-tips-color;
					height: 80rpx;

					.icon {
						margin-top: 6rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.bottom {
			margin-top: 20rpx;
			padding: 40rpx;
			// padding-right: 0;
			background-color: #ffffff;
			font-size: 28rpx;

			.tag {
				display: flex;

				.left {
					width: 160rpx;
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.tags {
						width: 140rpx;
						padding: 16rpx 8rpx;
						border: solid 2rpx $u-border-color;
						text-align: center;
						border-radius: 50rpx;
						margin: 0 10rpx 20rpx;
						display: flex;
						font-size: 28rpx;
						align-items: center;
						justify-content: center;
						color: $u-content-color;
						line-height: 1;
					}

					.active {
						color: #2979FF !important;
						border: solid 2rpx #2979FF !important;
					}

					.plus {
						//padding: 10rpx 0;
					}
				}
			}

			.default {
				margin-top: 50rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: solid 2rpx $u-border-color;
				line-height: 64rpx;

				.tips {
					font-size: 24rpx;
				}

				.right {}
			}
		}

		.login-btn {
			border-radius: 20px;
		}
	}
</style>